package LeetCode;

public class LC_125_ValidPalindrome {
    public static void main(String[] args) {

    }

    class Solution {
        public boolean isPalindrome(String s) {
            int i = 0, j = s.length() - 1;
            char head, tail;
            if (j < 0)
                return true;
            while (i < j) {
                head = s.charAt(i);
                tail = s.charAt(j);
                if (!Character.isLetterOrDigit(head)) i++;
                if (!Character.isLetterOrDigit(tail)) j--;
                if (Character.isLetterOrDigit(head) && Character.isLetterOrDigit(tail)) {
                    if (Character.toLowerCase(head) != Character.toLowerCase(tail)) return false;
                    i++;
                    j--;
                }
            }
            return true;
        }
    }
}
